<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<HEAD>
     <TITLE>!DOCTYPE</TITLE>
     <link rel="stylesheet" type="text/css" href="../../../ss/2.css" id="thecss">
     <script type="text/javascript" src="../../../scripts/csschange.js"></script>
</HEAD>

<BODY onload="readSS()">

<br>
<center>
<table border=3 cellpadding=5 cellspacing=0>
<tr>
    <td><h1 class="pagetitle">!DOCTYPE</h1>
        <b class="l3heading"><a href="../stats.htm#std">Standards Details:</a></b> Intrinsic feature of SGML/XML<br>
        <b><a href="../../../misc/suppkey.htm">Support Key:</a></b>
        [<b><i class="fs">2</i></b>|<b class="s">3</b>|<b class="s">3.2</b>|<b class="s">4</b>] 
        [<b class="s">X1</b>|<b class="s">X1.1</b>]
        [<b class="s">IE6</b>|<span class="ns">M</span>|<b><i class="fs">N6</i></b>|<b class="s">O7</b>]</td>
    <td><a href="#what">What is it?</a><br>
        <a href="#syntax">Syntax</a><br>
        <a href="#dtypeswitch">Doctype Switching</a>
    </td>
    <td><a href="#example">DTD Examples</a><br>
        <a href="#tips">Tips &amp; Tricks</a><br>
        <a href="#peculiar">Browser Peculiarities</a></td>
</tr>
<tr><td align=center colspan=3>
<font size=2>= <span class="sitetitle">Index DOT Html</span> by <a href="../../../misc/email.htm">Brian Wilson</a> =</font>
</td></tr>
</table>

<font size=2>
<a href="../../index.html">Main Index</a> |
<a href="../../tree/htmltree.htm">Element Tree</a> |
<a href="../../tagindex/a.htm">Element Index</a> |
<a href="../../supportkey/a.htm">HTML Support History</a></font>
</center>
<hr align="center" width="25%">

<!-- Inspiration/Thanks/Attributions on FPIs and others:
     Murray Altheim:  "FPI Road Trip!" 11/1996
     SGML On the Web:  Yuri Rubinsky and Murray Maloney
     Harold Driscoll: 'Popular Public HTML Document Type Definitions'
                      http://www.ccs.org/html/dtd/ [URL no longer available] -->
<br>
<a name="what"></a>
<dl>
<dt><big><b class="mainheading">What is it?</b></big>
    <dd>The !DOCTYPE declaration is a top-level tag-like reference known as a Public
        Text Identifier. It should appear at the very beginning of an HTML/XHTML
        document in order to identify the content of the document as
        conforming (theoretically) to a particular HTML DTD specification.
        Historically, including a DTD was not required by browsers; they just interpreted
        a document according to what elements and attributes it understood.  That
        has now changed (see the section on DOCTYPE switching below.)
        <br><br>

        The quoted segment within a !DOCTYPE declaration is called a Formal
        Public Identifier (FPI.) Every distinct DTD variation will have its
        own unique FPI string.
</dl>

<a name="syntax"></a>
<dl>
<dt><big><b class="mainheading">Syntax</b></big></dt>
<dt><b class="subheading">Typical HTML DOCTYPE statement:</b>
    <dd>
        <table cellpadding=0 cellspacing=0>
        <tr>
            <td align=center nowrap>&lt;<b class="tagname">!DOCTYPE</b>&#160;</td>
            <td align=center nowrap>&#160;<span class="tagattrib">HTML</span>&#160;</td>
            <td align=center nowrap>&#160;<span class="tagattrib">PUBLIC</span>&#160;</td>
            <td align=center nowrap>&#160;"<span class="alert2">-</span>//</td>
            <td align=center nowrap><span class="alert2">W3C</span>//</td>
            <td align=center nowrap><span class="alert2">DTD</span>&#160;</td>
            <td align=center nowrap>&#160;<span class="alert2">HTML 4.0 Transitional</span>//</td>
            <td align=center nowrap><span class="alert2">EN</span>"</td>
            <td align=center nowrap>&#160;&#160;"<span class="tagattrib">http://www.w3.org/TR/html4/loose.dtd</span>"&gt;</td>
        </tr>
        <tr>
            <td align=center>&#160;</td>
            <td align=center><sup><small class="alert">(1)</small></sup></td>
            <td align=center><sup><small class="alert">(2)</small></sup></td>
            <td align=center><sup><small class="alert">(3)</small></sup></td>
            <td align=center><sup><small class="alert">(4)</small></sup></td>
            <td align=center><sup><small class="alert">(5)</small></sup></td>
            <td align=center><sup><small class="alert">(6)</small></sup></td>
            <td align=center><sup><small class="alert">(7)</small></sup></td>
            <td align=center><sup><small class="alert">(8)</small></sup></td>
        </tr>
        </table>

<dt><b class="subheading">Annotated syntax:</b>
    <dd><table cellpadding=0 cellspacing=0>
        <tr nowrap>
            <td align=center nowrap>&lt;<b class="tagname">!DOCTYPE</b>&#160;</td>
            <td align=center nowrap>&#160;[<span class="tagattrib">Top&#160;Element</span>]&#160;</td>
            <td align=center nowrap>&#160;[<span class="tagattrib">Availability</span>]&#160;</td>
            <td align=center nowrap>&#160;&quot;[<span class="alert2">Registration</span>]//</td>
            <td align=center nowrap>[<span class="alert2">Organization</span>]//</td>
            <td align=center nowrap>[<span class="alert2">Type</span>]&#160;</td>
            <td align=center nowrap>&#160;[<span class="alert2">Label</span>]//</td>
            <td align=center nowrap>[<span class="alert2">Language</span>]&quot;</td>
            <td align=center nowrap>&#160;&#160;"[<span class="tagattrib">URL</span>]"&gt;</td>            
        </tr>
        <tr nowrap>
            <td align=center>&#160;</td>
            <td align=center><sup><small class="alert">(1)</small></sup></td>
            <td align=center><sup><small class="alert">(2)</small></sup></td>
            <td align=center><sup><small class="alert">(3)</small></sup></td>
            <td align=center><sup><small class="alert">(4)</small></sup></td>
            <td align=center><sup><small class="alert">(5)</small></sup></td>
            <td align=center><sup><small class="alert">(6)</small></sup></td>
            <td align=center><sup><small class="alert">(7)</small></sup></td>
            <td align=center><sup><small class="alert">(8)</small></sup></td>
        </tr>
        </table>

<dt><b class="subheading">Explanation</b>
    <dd><b class="l3heading">General</b> : A pair of forward slash characters (&quot;//&quot;)
        is used as delimiters between keyword fields in the FPI declaration.
    <dd><b class="l3heading">(1)</b> : [<span class="alert2">Top&#160;Element</span>] -
        Indicates the top level element type declared in the DTD; for HTML it is
        &lt;<b class="alert">html</b>&gt;.
    <dd><b class="l3heading">(2)</b> : [<span class="alert2">Availability</span>] -
        field indicates whether the identifier is a publicly accessible object
        (PUBLIC) or a system resource (SYSTEM) such as a local file or URL. HTML/XHTML
        DTDs are specified by PUBLIC identifiers.
    <dd><b class="l3heading">(3)</b> : [<span class="alert2">Registration</span>] - Indicated
        by either a plus (&quot;+&quot;) or minus (&quot;-&quot;). A plus symbol indicates
        that the organization name that follows is ISO-registered. A minus sign indicates
        the organization name is not registered. The IETF and W3C are not registered ISO
        organizations and thus use a &quot;-&quot;.
    <dd><b class="l3heading">(4)</b> : [<span class="alert2">Organization</span>] - This is the
        &quot;OwnerID&quot; - a unique label indicating the name of the entity or organization
        responsible for the creation and/or maintenance of the artifact (DTD, etc.) being
        referenced by the DOCTYPE. The IETF and W3C are the two originating organizations of the
        official HTML/XHTML DTDs.
    <dd><b class="l3heading">(5)</b> : [<span class="alert2">Type</span>] - This is the
        &quot;Public Text Class&quot; - the type of object being referenced. There are
        many different keywords possible here, but in the case of an HTML/XHTML DTD, it is
        &quot;DTD&quot; - a Document Type Definition.
    <dd><b class="l3heading">(6)</b> : [<span class="alert2">Label</span>] - This is the
        &quot;Public Text Description&quot; - a unique descriptive name for the public
        text (DTD) being referenced. If the public text changes for any reason, a new Public
        Text Description string should be created for it.
    <dd><b class="l3heading">(7)</b> : [<span class="alert2">Language</span>] - This is
        the &quot;Public Text Language&quot;; the natural language encoding system used
        in the creation of the referenced object. It is written as an ISO 639 language
        code (uppercase, two letters.) HTML/XHTML DTDs are usually (always?) written in
        English (&quot;EN&quot;.)
    <dd><b class="l3heading">(8)</b> : [<span class="alert2">URL</span>] - This is
        the optional explicit URL to the DTD being referenced.
</dl>

<a name="dtypeswitch"></a>
<dl>
<dt><big><b class="mainheading">!DOCTYPE Switching</b></big>
<dt><b class="subheading">The Need</b>
    <dd>Now that it is many years since the web exploded in popularity, it now has 
        a huge legacy of existing content on untold millions of web pages 
        all over the planet. These pages were all created at different times, before 
        many of the current web standards were in place. Many of these pages also 
        were written by hand, usually by authors that were not aware of what the 
        correct syntax or standards actually were. Many of these same authors also 
        often had (and have) a tendency to write markup, and test the result in a 
        single browser without validating their code. In the past, these browsers 
        had many behaviors that did not comply with the W3C standards, and many 
        pages on the web rely on some of these buggy or non-standards behaviors.        
        Now that the W3C standards receive more and more attention, and the browsers 
        move to be more compliant with these evolving standards, a big problem has arisen.
        <br><br>

        Old browsers would just read whatever page that was thrown at it and try to
        render it as best that it could, including any browser extensions that it
        understood. If a new browser version were to move to a strictly standards-compliant
        rendering behavior, <em>millions</em> of pages on the web would instantly 
        be rendered "incorrectly" (according to the original intent of the author, 
        misguided though that might be.) Authors, and readers alike would most-likely 
        blame the <em>browser</em> as being "buggy"...no browser could afford to 
        do this and expect to survive for very long. But - there was a <em>REASON</em> 
        that these standards have come to be accepted - they are gigantic leap forward 
        in web page structure and organization. Do we just continue to accept the 
        mish-mash of the historical quagmire that was the HTML in web pages of old?

<dt><b class="subheading">The Solution</b>
    <dd>The Macintosh version of Internet Explorer 5.0 began a trend in March 2000
        that all the major browsers now support to some degree. To allow for the 
        huge amount of legacy documents <em>AND</em> all current and new standards-based 
        documents, browsers now finally pay attention to the !DOCTYPE declaration at
        the beginning of an HTML/XHTML document. Depending on which !DOCTYPE is 
        used, the browser will either attempt to render the document according 
        to the W3C standards as close as possible or use the legacy rendering 
        behavior that many older pages rely on.
        <br><br>
        
        These two rendering modes are referred to generally as "standards mode" 
        and "quirks mode" (it should be pretty obvious which one makes a browser
        behave as close as possible to the W3C standards. 8-}) Now - how is a 
        browser to choose which rendering mode to use?
        <br><br>
        
        <b class="alert">The general rules for choosing:</b><br>
        Most older documents often do not have a !DOCTYPE at all, since its 
        presence was not required in order to render the web page in older browsers.
        Older documents that DO have a !DOCTYPE present usually reference older 
        DTDs. For !DOCTYPEs that reference known-older DTDs and documents that carry 
        no !DOCTYPE at all, quirks mode is always chosen. When we get to HTML 4,
        things become interesting - some DOCTYPEs select standards mode, and some
        select quirks mode.

<dt><b class="subheading">More information</b>
    <dd>I purposefully will not get into the details of precisely which DTDs produce
        quirks mode or standards mode, nor will I get into the details of what those
        exact differences are. The information on these two points would fill many 
        pages and would doubtlessly change over time (not a headache I want to take on.) 
        This sort of information should and <em>MUST</em> come from the browser 
        makers themselves, in my opinion (this is one documentation area where 
        the browser makers must, and thankfully HAVE delivered to the authoring 
        community so far. See the Doctype Switching links below for more information
        on this topic. 
        <br><br>
        
        <b class="alert">Final caveat:</b><br>
        Although all the major browsers now have these two rendering modes, the 
        browsers still have bugs, behaviors and variations between them on what 
        is included when each mode is used. Test your content as widely as possible.
</dl>

<a name="example"></a>
<dl>
<dt><big><b class="mainheading">!DOCTYPE Examples</b></big>
<dt><b class="subheading">HTML 2.0</b>
    <dd><div class="example">&#160;&#160;&lt;<b class="tagname">!DOCTYPE</b>
        <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//IETF//DTD HTML 2.0 Level 2//EN</span>&quot;&gt;<br>
        &#160;&#160;&lt;<b class="tagname">!DOCTYPE</b>
        <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//IETF//DTD HTML//EN</span>&quot;&gt;<br>
        &#160;&#160;&lt;<b class="tagname">!DOCTYPE</b>
        <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//IETF//DTD HTML 2.0//EN</span>&quot;&gt;<br>
        &#160;&#160;&lt;<b class="tagname">!DOCTYPE</b>
        <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//IETF//DTD HTML Level 2//EN</span>&quot;&gt;</div>

<dt><b class="subheading">HTML 3.0</b>
    <dd><div class="example">&#160;&#160;&lt;<b class="tagname">!DOCTYPE</b>
        <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//IETF//DTD HTML 3.0//EN</span>&quot;&gt;</div>

<dt><b class="subheading">HTML 3.2</b>
    <dd><div class="example">&#160;&#160;&lt;<b class="tagname">!DOCTYPE</b>
        <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD HTML 3.2 Final//EN</span>&quot;&gt;</div>

<dt><b class="subheading">HTML 4.01</b>
    <dd><div class="example">&#160;&#160;<span class="alert">[Strict DTD]:</span> 
        &lt;<b class="tagname">!DOCTYPE</b> <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD HTML 4.01//EN</span>&quot; 
        "<span class="alert2">http://www.w3.org/TR/html4/strict.dtd</span>"&gt;<br>
        &#160;&#160;<span class="alert">[Transitional DTD]:</span> 
        &lt;<b class="tagname">!DOCTYPE</b> <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD HTML 4.01 Transitional//EN</span>&quot; 
        "<span class="alert2">http://www.w3.org/TR/html4/loose.dtd</span>"&gt;<br>
        &#160;&#160;<span class="alert">[Frameset DTD]:</span>
        &lt;<b class="tagname">!DOCTYPE</b> <span class="tagattrib">HTML PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD HTML 4.01 Frameset//EN</span>&quot;
        "<span class="alert2">http://www.w3.org/TR/html4/frameset.dtd</span>"&gt; </div>

<dt><b class="subheading">XHTML 1.0</b>
    <dd><div class="example">&#160;&#160;<span class="alert">[Strict DTD]:</span> 
        &lt;<b class="tagname">!DOCTYPE</b> <span class="tagattrib">html PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD XHTML 1.0 Strict//EN</span>&quot; 
        "<span class="alert2">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</span>"&gt;<br>
        &#160;&#160;<span class="alert">[Transitional DTD]:</span> 
        &lt;<b class="tagname">!DOCTYPE</b> <span class="tagattrib">html PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD XHTML 1.0 Transitional//EN</span>&quot; 
        "<span class="alert2">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</span>"&gt;<br>
        &#160;&#160;<span class="alert">[Frameset DTD]:</span>
        &lt;<b class="tagname">!DOCTYPE</b> <span class="tagattrib">html PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD XHTML 1.0 Frameset//EN</span>&quot;
        "<span class="alert2">http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd</span>"&gt; </div>

<dt><b class="subheading">XHTML 1.1</b>
    <dd><div class="example">&#160;&#160;&lt;<b class="tagname">!DOCTYPE</b>
        <span class="tagattrib">html PUBLIC</span>
        &quot;<span class="alert2">-//W3C//DTD XHTML 1.1//EN</span>&quot;&gt;</div>
</dl>


<a name="tips"></a>
<big><b class="mainheading">Tips &amp; Tricks</b></big>
<ul>
    <li>Some HTML validation tools will need to have the !DOCTYPE declaration present 
        in order to choose the proper DTD to validate against.
    <li>Using a !DOCTYPE declaration also allows tools (such as SGML browsers or 
        document validators) to view your document. Some of these tools can play 
        vital roles in managing HTML documents.
    <li>SGML tools can also use URLs as FPI references to DTDs. The SYSTEM keyword 
        in the Public Text Identifier indicates that the FPI may be a URL reference. 
        Example:<br>
        &lt;<b class="tagname">!DOCTYPE</b> <span class="tagattrib">HTML SYSTEM</span>
        &quot;http://www.w3.org/DTD/HTML4-strict.dtd&quot;&gt;
</ul>

<a name="peculiar"></a>
<big><b class="mainheading">Browser Peculiarities</b></big>
<ul>
    <li>[Bug described elsewhere] IE6 and Opera 7.0x: If there is anything before the &lt;!DOCTYPE&gt; 
        declaration, quirks mode will be used. In the case of In an XML document (including XHTML), 
        it is syntactically correct and recommended to have the XML declaration 
        (eg: &lt;?xml version="1.0" ?&gt;) come before any other content. This means 
        that XHTML documents that use the XML declaration, even if they carry a 
        current and/or strict DTD, will use Quirks mode.
    <li>After Mozilla 1.0 (Netscape 7.0) was released, a third specialized mode, 
        called "almost standards" mode was created. Please see Mozilla's documentation 
        on !DOCTYPE switching for more details on the authoring implications.
    <li>Historically, browsers did not care about doctypes, because they were 
        expecting the content of the documents to be HTML and they would only 
        interpret what they could in a single way. That has now changed with the 
        adoption of doctype switching behaviors in all the popular browsers (beginning 
        in the versions indicated above) to allow for full standards adoption while 
        also allowing for legacy behavior with older content.
    <li><b class="alert">Note:</b> This is not really a browser peculiarity about 
        doctypes, it is a peculiarity about this particular page in Netscape 4.x.
        If you are using one of these browsers and most of the above content is 
        invisible, you are seeing an interesting and elusive Netscape rendering bug. 
        A fix that works for me is to expand the browser window (if window is not 
        already maximized and resolution permits) at least wide enough for the entire 
        "Annotated Syntax" line to be visible on a single line. I have been trying to 
        track down the reason for this behavior for a long time but it has been 
        exceedingly hard to reproduce... this fix works on <em>MY</em> machine at 
        least. Strange bug.</span>

</ul>

<a name="related"></a>
<br>
<big><b class="mainheading">Related Sites</b></big>
<dl>
<dt><b class="subheading">Official References</b>
<dt><a href="http://www.rfc-editor.org/rfc/rfc1866.txt" class="relevant">http://www.rfc-editor.org/rfc/rfc1866.txt</a>
    <dd><span class="relevant">RFC 1866: The HTML 2.0 specification (plain text)</span>
<dt><a href="http://www.w3.org/MarkUp/html-spec/" class="relevant">http://www.w3.org/MarkUp/html-spec</a>
    <dd><span class="relevant">The web version of the HTML 2.0 (RFC 1866) specification</span>
<dt><a href="http://www.w3.org/MarkUp/Wilbur/" class="relevant">http://www.w3.org/MarkUp/Wilbur/</a>
    <dd><span class="relevant">The HTML 3.2 (Wilbur) recommendation</span>
<dt><a href="http://www.w3.org/TR/html4/" class="relevant">http://www.w3.org/TR/html4/</a>
    <dd><span class="relevant">The HTML 4.0 recommendation</span>
<dt><a href="http://www.w3.org/TR/html401/" class="relevant">http://www.w3.org/TR/html401/</a>
    <dd><span class="relevant">The HTML 4.01 recommendation</span>
<dt><a href="http://www.w3.org/TR/xhtml1/" class="relevant">http://www.w3.org/TR/xhtml1/</a>
    <dd><span class="relevant">The XHTML 1.0 recommendation</span>
<dt><a href="http://www.w3.org/TR/xhtml11/" class="relevant">http://www.w3.org/TR/xhtml11/</a>
    <dd><span class="relevant">The XHTML 1.1 recommendation</span>
<br><br>
<!-- http://www.ccs.org/html/dtd/ -->
<!-- Harold Driscoll's excellent listing of popular public HTML Document
    Type Definitions [Had to delete the link to this excellent site because
 the pages no longer exist - if you know of a new pointer, please let me know.] -->
</dl>

<big><b class="mainheading">!DOCTYPE Switching links</b></big>
<dl>
<dt><b class="subheading">Official References</b>
<dt><a href="http://www.mozilla.org/docs/web-developer/quirks/doctypes.html" 
       class="relevant">http://www.mozilla.org/docs/web-developer/quirks/doctypes.html</a>
    <dd><span class="relevant">Mozilla's documentation and table on which DTDs trigger which mode (by David Baron)</span>
<dt><a href="http://dbaron.org/mozilla/quirklist" class="relevant">http://dbaron.org/mozilla/quirklist</a>
    <dd><span class="relevant">David Baron's list of differences between quirks and standards mode (probably can be called "official")</span>
<dt><a href="http://msdn.microsoft.com/library/en-us/dnie60/html/cssenhancements.asp?frame=true" 
       class="relevant">http://msdn.microsoft.com/library/en-us/dnie60/html/cssenhancements.asp?frame=true</a>
    <dd><span class="relevant">Internet Explorer's "Enhancements in IE6": documentation and mode/behavior differences</span>
<dt><a href="http://www.opera.com/docs/specs/doctype/" class="relevant">http://www.opera.com/docs/specs/doctype/</a>
    <dd><span class="relevant">Opera's documentation and mode/behavior differences</span>
<br><br>

<dt><b class="subheading">Other References</b>

<dt><a href="http://gutfeldt.ch/matthias/articles/doctypeswitch.html" 
       class="relevant">http://gutfeldt.ch/matthias/articles/doctypeswitch.html</a>
    <dd><span class="relevant">Matthias Gutfeldt's "Doctype switching and standards 
        compliance: An overview"; a great up-to-date discussion of the topic with 
        many additional links for more information.</span>
<dt><a href="http://www.hut.fi/u/hsivonen/doctype.html" 
       class="relevant">http://www.hut.fi/u/hsivonen/doctype.html</a>
    <dd><span class="relevant">Henri Sivonen's "Activating the right layout mode 
        using the Doctype declaration"; another great discussion of the topic.</span>
</dl>

<br>
<a href="../../../misc/copyright.htm">Boring Copyright Stuff...</a>

</BODY>
</HTML>
